//高阶函数-函数作为参数

function forEach(array, fn) {
  for (let i = 0; i < array.length; i++) {
    fn(array[i]);
  }
}

//测试
// let arr = [1,2,3]

// forEach(arr, item => console.log(item))

//filter
function filter(array, fn) {
  let res = [];
  for (let i = 0; i < array.length; i++) {
    if (fn(array[i])) {
      res.push(array[i]);
    }
  }
  return res;
}

//测试
let arr = [1, 6, 5, 3, 8];
let res = filter(arr, (item) => {
  return item % 2 == 0;
});
console.log(res)
